import { ref } from "vue";
import { getFileLabels } from "@/api/know.js";

const treeData = ref();

export const initDic = () => {
  getFileLabels().then((res) => {
    const d = res.data.labels.filter((item) => item != null);
    treeData.value = d.map((item) => ({ value: item, label: item }));
  });
};

export const form = [
  {
    label: "文件名",
    field: "fileName",
    component: "Input",
    span: 6,
    componentProps: {
      maxlength: 50,
      placeholder: "请输入文件名",
      style: { width: "95%" },
    },
  },
];

export const columns = [
  {
    label: "文件名",
    field: "fileName",
    width: 400,
    componentProps: {
      fixed: "left",
      align: "center",
      showOverflowTooltip: true,
    },
  },
  {
    label: "版本号",
    field: "fileVersion",
    componentProps: {
      align: "center",
    },
  },
  {
    label: "上传时间",
    field: "createTime",
    componentProps: {
      align: "center",
    },
  },
  {
    label: "文件大小",
    field: "fileSize",
    componentProps: {
      align: "center",
    },
  },
  {
    label: "格式",
    field: "fileFormat",
    componentProps: {
      align: "center",
    },
  },
  {
    label: "操作",
    field: "operations",
    componentProps: {
      fixed: "right",
      align: "center",
    },
  },
];

export const config = ref([
  {
    label: "分类",
    field: "fileLabel",
    component: "CSelect",
    span: 24,
    componentProps: {
      maxlength: 50,
      style: { width: "100%" },
      options: treeData,
      filterable: true,
    },
  },
  {
    label: "文件",
    field: "parts",
    component: "Upload",
    span: 24,
    componentProps: {
      maxlength: 50,
      placeholder: "请选择文件",
      style: { width: "100%" },
      multiple: true,
      options: [],
    },
  },
]);
export const rules = {
  fileLabel: [
    {
      required: true,
      message: "请输入分类",
      trigger: "blur",
    },
  ],
  parts: [
    {
      required: true,
      message: "请选择文件",
      trigger: "blur",
    },
  ],
};
